package service.impl;

import mapper.ComputerRoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import entity.Computerroom;
import service.ComputerRoomService;
import utils.Page;

import java.util.List;

@Service("computerRoomService")
public class ComputerRoomServiceImpl implements ComputerRoomService {
    @Autowired
    private ComputerRoomMapper computerRoomMapper;
    @Override
    public Page<Computerroom> getComputerRooms(Computerroom computerroom, Integer pageNo, Integer pageSize) {
        Page<Computerroom> page = new Page<Computerroom>();
        page.setPageSize(pageSize);
        // 查询总数，计算总页数
        Integer count = computerRoomMapper.count(computerroom);
        page.setTotalCount(count);
        page.setPageNo(pageNo);
        // 查询分页数据
        Integer pageBegin=(pageNo-1)*pageSize;
        List<Computerroom> data = computerRoomMapper.getComputerRooms(computerroom, page.offset(), page.getPageSize());
        page.setData(data);
        return page;
    }

    @Override
    public boolean insert(Computerroom computerroom) {
        return computerRoomMapper.insert(computerroom) >0;
    }

    @Override
    public boolean update(Computerroom computerroom) {
        return computerRoomMapper.update(computerroom) >0;
    }


    @Override
    public boolean delete(Integer roomId) {
        return computerRoomMapper.delete(roomId) > 0;
    }

    @Override
    public Computerroom getById(Long id) {
        return computerRoomMapper.getById(id);
    }

    @Override
    public Computerroom findByAccount(String roomName) {
        return computerRoomMapper.findByAccount(roomName);
    }


}
